#ifndef TB67S109_H
#define TB67S109_H
#include <SN74AHC595.h>

namespace toshiba
{
  
typedef struct
{
  union
  {
    struct
    {
      uint8_t s0  :1;
      uint8_t s1  :1;
      uint8_t s2  :1;
      uint8_t m0  :1;
      uint8_t m1  :1;
      uint8_t m2  :1;
      uint8_t en  :1;
      uint8_t dir :1;
    };
    uint8_t data[1];
    uint8_t value;
  };
  
}tb67s109a_t;


class TB67S109A
{
public:
    using smc_clock_callback = void (*)(bool);
    enum class RotationDirection{Backward,Forward,None};
    TB67S109A(tb67s109a_t& _driver,ti::SN74AHC595& hc595,smc_clock_callback cb);
    ~TB67S109A();

    void begin();

    void set_direction(RotationDirection dir=RotationDirection::None);

    void enable_clock();

    void disable_clock();

    void set_emergency_stop(bool dir_forward=true);

    tb67s109a_t& driver()
    { 
      return _driver;
    }

private:
    tb67s109a_t& _driver;
    ti::SN74AHC595& _hc595;
    smc_clock_callback _cb;
    RotationDirection _dir;
};

}

#endif